﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PressureTest
{
    public partial class SetDBForm : Form
    {
        /// <summary>配置工具
        /// 
        /// </summary>
        Config config = new Config();

        public SetDBForm()
        {
            InitializeComponent();
        }

        private void SetDBForm_Load(object sender, EventArgs e)
        {
            HostTextBox.Text = config.DBHost;
            PortTextBox.Text = config.DBPort;
            NameTextBox.Text = config.DBName;
            UserTextBox.Text = config.DBUser;
            PwdTextBox.Text = config.DBPwd;
        }

        /// <summary>确定
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            if (!HostTextBox.Text.IsIP4())
            {
                Alert.Error("请输入正确的IP地址");
                return;
            }
            config.DBHost = HostTextBox.Text;

            if (!PortTextBox.Text.IsNumber())
            {
                Alert.Error("请输入正确的端口");
                return;
            }
            config.DBPort = PortTextBox.Text;

            if (!NameTextBox.Text.IsValid())
            {
                Alert.Error("请输入正确的数据库名称");
                return;
            }
            config.DBName = NameTextBox.Text;

            if (!UserTextBox.Text.IsValid())
            {
                Alert.Error("请输入正确的用户");
                return;
            }
            config.DBUser = UserTextBox.Text;

            if (!PwdTextBox.Text.IsValid())
            {
                Alert.Error("请输入正确的密码");
                return;
            }
            config.DBPwd = PwdTextBox.Text;
            this.Close();
        }
    }
}
